package com.third.clock.common;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesUtils {
	
	private static SharedPreferencesUtils sharedPreferencesUtils;
	
	public static final String USERNAME_KTY="username";

	public static final String PASSWORD_KEY="password";

	SharedPreferences sp;
	
	
	private SharedPreferencesUtils(Context context){
		 sp = context.getSharedPreferences("thrid_clock", Context.MODE_PRIVATE);
	}
	
	public static SharedPreferencesUtils getInstance(Context context){
		if(null==sharedPreferencesUtils){
			synchronized (SharedPreferencesUtils.class) {
				if(null==sharedPreferencesUtils){
					sharedPreferencesUtils=new SharedPreferencesUtils(context);
				}
			}
		}
		
		return sharedPreferencesUtils;
	}
	
	
	public void putIntValue(String key,int value){
		if(null!=sp){
			sp.edit().putInt(key, value).commit();
		}
	}
	
	public int getIntValue(String key,int defalut){
		int value=-1;
		if(null!=sp){
			value=sp.getInt(key, defalut);
		}
		return value;
	}
	
	public void putBooleanValue(String key,boolean value){
		if(null!=sp){
			sp.edit().putBoolean(key, value).commit();
		}
	}
	
	public boolean getBooleanValue(String key){
		boolean value=false;
		if(null!=sp){
			value=sp.getBoolean(key, false);
		}
		return value;
	}


	public void putStringValue(String key,String value){
		if(null!=sp){
			sp.edit().putString(key, value).commit();
		}
	}

	public String getStringValue(String key,String defValue){
		String value=defValue;
		if(null!=sp){
			value=sp.getString(key, defValue);
		}
		return value;
	}

}
